import { post } from "@/utils/request";


export async function GoodsList(feature: string | null, price: string | null): Promise<GoodsResponse> {
  try {
    const url = `/api/goods/goodlist`;
    const accessToken = localStorage.getItem('access_token');
    const headers = new Headers();
    headers.append('Authorization', `${accessToken}`);
    headers.append('Content-Type', 'application/json');
    // 构造请求参数对象
    const body = {
      feature,
      price,
    };

    // 发送 POST 请求
    const response = await fetch(url, {
      method: 'POST',
      headers: headers,
      body: JSON.stringify(body), // 将请求参数对象转换为 JSON 字符串
    });

    // 检查响应是否成功
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }

    // 解析响应数据
    const data = await response.json();
    return data;
  } catch (error) {
    console.error('Error fetching goods list:', error);
    throw error;
  }
}
